package cn.edu.cug.cs.gtl.gsm;

import cn.edu.cug.cs.gtl.gsm.disk.DiskStorageManager;
import cn.edu.cug.cs.gtl.gsm.memory.MemoryStorageManager;
import cn.edu.cug.cs.gtl.gsm.mongo.MongoStorageManager;
import cn.edu.cug.cs.gtl.gsm.jdbc.oracle.OracleStorageManager;
import cn.edu.cug.cs.gtl.gsm.jdbc.mysql.MysqlStorageManager;
import cn.edu.cug.cs.gtl.gsm.jdbc.postgres.PostgresStorageManager;
import cn.edu.cug.cs.gtl.io.storage.StorageManager;

import java.sql.Connection;

public class StorageManagers {
    /**
     *
     * @param pageSize
     * @return
     */
    public static StorageManager createMemoryStorageManager(int pageSize){
        return new MemoryStorageManager(1024*1024,pageSize);
    }

    /**
     *
     * @param collectionSize
     * @param pageSize
     * @return
     */
    public static StorageManager createMemoryStorageManager(long collectionSize , int pageSize){
        return new MemoryStorageManager(collectionSize,pageSize);
    }

    /**
     *
     * @param baseName
     * @param collectionSize
     * @param pageSize
     * @param overWrite
     * @return
     */
    public static StorageManager createDiskStorageManager(
            String baseName, long collectionSize,int pageSize, boolean overWrite) {
        try {

            return new DiskStorageManager( baseName,  collectionSize, pageSize,  overWrite);
        }
        catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    /**
     *
     * @param mongoClientURI
     * @param baseName
     * @param collectionSize
     * @param pageSize
     * @param overWrite
     * @return
     */
    public static StorageManager createMongoStorageManager(String mongoClientURI,
            String baseName, long collectionSize,int pageSize, boolean overWrite) {
        try {
            return new MongoStorageManager( mongoClientURI,baseName,  collectionSize, pageSize,  overWrite);
        }
        catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    /**
     *
     * @param connection
     * @param baseName
     * @param collectionSize
     * @param pageSize
     * @param overWrite
     * @return
     */
    public static StorageManager createPostgresStorageManager(Connection connection,
                                                              String baseName, long collectionSize, int pageSize, boolean overWrite) {
        try {
            return new PostgresStorageManager(connection,baseName,  collectionSize, pageSize,  overWrite);
        }
        catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    public static StorageManager createPostgresStorageManager(String  connectionString,String user, String password,
                                                              String baseName, long collectionSize, int pageSize, boolean overWrite) {
        try {
            return new PostgresStorageManager(  connectionString, user,  password,
                     baseName,  collectionSize,  pageSize,  overWrite) ;
        }
        catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    public static StorageManager createMysqlStorageManager(Connection connection,
                                                              String baseName, long collectionSize, int pageSize, boolean overWrite) {
        try {
            return new MysqlStorageManager(connection,baseName,  collectionSize, pageSize,  overWrite);
        }
        catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    public static StorageManager createMysqlStorageManager(String  connectionString,String user, String password,
                                                              String baseName, long collectionSize, int pageSize, boolean overWrite) {
        try {
            return new MysqlStorageManager(  connectionString, user,  password,
                    baseName,  collectionSize,  pageSize,  overWrite) ;
        }
        catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    public static StorageManager createOracleStorageManager(Connection connection,
                                                           String baseName, long collectionSize, int pageSize, boolean overWrite) {
        try {
            return new OracleStorageManager(connection,baseName,  collectionSize, pageSize,  overWrite);
        }
        catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

    public static StorageManager createOracleStorageManager(String  connectionString,String user, String password,
                                                           String baseName, long collectionSize, int pageSize, boolean overWrite) {
        try {
            return new OracleStorageManager(  connectionString, user,  password,
                    baseName,  collectionSize,  pageSize,  overWrite) ;
        }
        catch (Exception e){
            e.printStackTrace();
            return null;
        }
    }

}
